import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
	  token:localStorage.getItem('token'),
	  username:""
  },
  getters: {
	  // 登录状态
	  isLogin(state) {
		  return !!state.token
	  },
	  // 用户信息是否存在
	  hasInfo(state) {
		  return !!state.username
	  }
  },
  mutations: {
	  // 设置token
	  setToken:(state,token) => {
		   state.token = token
	  },
	  // 设置用户名
	  setUsername:(state,username) => {
		  state.username = username
	  }
  },
  actions: {},
  modules: {},
});
